import Vue from 'vue'
import Router from 'vue-router'
import Layout from '../Layout.vue'
import {Article,
  Banner,
  Classification,
  Global,
  Website,
  Operating,
  PlatformDelivery,
  PlatformGoods,
  PurchaseDelivery,
  PurchaseGoods,
  PromotionData,
  PromotionRecord,
  PaymentOrder,
  PaymentSwitching,
  BoxDetails,
  BoxGrouping,
  PurchaseConfig,
  Water,
  WhiteList,
  AccessRecords,
  Ordinary,
  Payment,
  Special,
  Chart,
  Operation,
  Login,
} from '../components/index.js'
import { Form } from 'element-ui'

Vue.use(Router)

var router = new Router({
  routes: [
    {
      path: '/',
      component:Login,
    },
    {
      path: '/',
      component: Layout,
      children: [
        {
          path:'index',
          redirect: '/Chart'
        },
        {
          path: 'Chart',
          component:Chart,
        },
        {
          path: 'Operation',
          component:Operation
        },
        {
          path: 'Operating',
          component:Operating
        },
        {
          path: 'Banner',
          component:Banner
        },
        {
          path: 'Classification',
          component:Classification
        },
        {
          path: 'Global',
          component:Global
        },
        {
          path: 'Website',
          component:Website
        },
        {
          path: 'PlatformDelivery',
          component:PlatformDelivery
        },
        {
          path: 'PlatformGoods',
          component:PlatformGoods
        },
        {
          path: 'PurchaseDelivery',
          component:PurchaseDelivery
        },
        {
          path: 'PurchaseGoods',
          component:PurchaseGoods
        },
        {
          path: 'PromotionData',
          component:PromotionData
        },
        {
          path: 'PromotionRecord',
          component:PromotionRecord
        },
        {
          path: 'PaymentOrder',
          component:PaymentOrder
        },
        {
          path: 'PaymentSwitching',
          component:PaymentSwitching
        },
        {
          path: 'BoxDetails',
          component:BoxDetails
        },
        {
          path: 'BoxGrouping',
          component:BoxGrouping
        },
        {
          path: 'PurchaseConfig',
          component:PurchaseConfig
        },
        {
          path: 'Water',
          component:Water
        },
        {
          path: 'WhiteList',
          component:WhiteList
        },
        {
          path: 'AccessRecords',
          component:AccessRecords
        },
        {
          path: 'Ordinary',
          component:Ordinary
        },
        {
          path: 'Payment',
          component:Payment
        },
        {
          path: 'Special',
          component:Special
        },
        {
          path: 'Article',
          component:Article
        }
      ] ,
     
    },
    
  ]
})


router.beforeEach((to, from, next) => {
    var token = localStorage.getItem('sessionId')
    if(token || to.fullPath=="/" ){
      next()
    }else{
      next()
        router.push({
          path:'/'
      })
    }
})

export default router